<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<title>添加档案信息</title>
<link rel="stylesheet" type="text/css"
	href="../assets/admin/layui/css/layui.css" />
<link rel="stylesheet" type="text/css"
	href="../assets/admin/css/admin.css" />
</head>

<body>
	<div class="page-content-wrap" id="achivesAdd">

		<form class="layui-form" action="" id="">
			<div class="layui-form-item">
				<label class="layui-form-label">姓名</label>
				<div class="layui-input-block">
					<input type="text" name="empName" lay-verify="required|empName"
						autocomplete="off" placeholder="请输入姓名" class="layui-input">
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">性别</label>
				<div class="layui-input-block">
					<select name="empSex" lay-verify="required">
						<option value="">请选择性别</option>
						<option value="男">男</option>
						<option value="女">女</option>
					</select>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">住址</label>
				<div class="layui-input-block">
					<input type="text" name="empAddress" lay-verify="required|empAddress"
						placeholder="请输入住址" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">出生日期</label>
				<div class="layui-input-block">
					<input type="text" class="layui-input" lay-verify="required|empBirth"
						id="empBirth" name="empBirth" placeholder="选择出生日期">
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">身份证号</label>
				<div class="layui-input-block">
					<input type="text" name="empCard" lay-verify="required|empCard"
						placeholder="请输入身份证号" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">入职日期</label>
				<div class="layui-input-block">
					<input type="text" class="layui-input" name="entryTime" lay-verify="required"
						id="entryTime" placeholder="请选择入职日期">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">职称</label>
				<div class="layui-input-block">
					<input type="text" name="empTitles" lay-verify="required|empTitles"
						placeholder="请输入职称" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">手机号</label>
				<div class="layui-input-block">
					<input type="text" name="mobile" lay-verify="required|mobile"
						placeholder="请输入手机号" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">毕业时间</label>
					<div class="layui-input-block">
					<input type="text" class="layui-input" name="graduationTime"  lay-verify="required"
						id="graduationTime" placeholder="请选择毕业时间">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">毕业院校</label>
				<div class="layui-input-block">
					<input type="text" name="graduationShcool" lay-verify="required|graduationShcool"
						placeholder="请输入毕业院校" autocomplete="off" class="layui-input">
				</div>
			</div>
			
			<div class="layui-form-item">
				<label class="layui-form-label">学历</label>
				<div class="layui-input-block">
					<select name="education" lay-verify="required">
						<option value="">请选择学历</option>
						<option value="1">大专</option>
						<option value="2">本科</option>
						<option value="3">硕士</option>
						<option value="4">博士</option>
					</select>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">请选择部门</label>
				<div class="layui-input-block">
					   <select name="empDepart" id="empDepart" lay-verify="required"  lay-search="">
          				<option value="">请选择部门</option>
       				 </select>
				</div>
			</div>
			
			<div class="layui-form-item m-login-btn" style="text-align: center">
				<div class="layui-inline">
					<button class="layui-btn layui-btn-normal" lay-submit
						lay-filter="addAchives">添加档案</button>
				</div>
				<div class="layui-inline">
					<button type="reset"
						class="layui-btn layui-btn-primary  site-demo-active"
						data-type="reset">取消添加</button>
				</div>
			</div>
		</form>

		<hr></hr>
		<h5 style="text-align: center;">@2019.HR</h5>
	</div>
	<script src="../assets/admin/layui/layui.all.js" type="text/javascript"
		charset="utf-8"></script>
	<script>
		layui.use([ 'form', 'layedit', 'laydate' ],
		function() {
			var form = layui.form, layer = layui.layer, layedit = layui.layedit;
			var $ = layui.jquery;
			var laydate = layui.laydate;
			//创建一个编辑器
			var editIndex = layedit.build('LAY_demo_editor');
			//自定义验证规则
			form.verify({
				empName : [ /^[\S]{2,10}$/, '姓名长度必须2到10位之间' ],
				empAddress:[ /^[\S]{1,20}$/, '地址长度不可超过20' ],
				empCard:[ /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/, '请输入正确的身份证号码' ],
				empTitles: [ /^[\S]{1,10}$/, '职称长度不可超过10位' ],
				graduationShcool:[ /^[\S]{1,20}$/, '毕业院校长度不可超过20' ],
				mobile:[ /^1(3|4|5|7|8)\d{9}$/, '请输入正确的手机号' ],
				content : function(value) {
					layedit.sync(editIndex);
				}
			});
			//出生日期
	       laydate.render({
				elem : '#empBirth'
	            ,format:'yyyy-MM-dd'
	            ,type:'date'
	            ,trigger: 'click'
	        });
	   		//入职日期
	       laydate.render({
				elem : '#entryTime'
	            ,format:'yyyy-MM-dd'
	            ,type:'date'
	            ,trigger: 'click'
	        });
	   		//毕业时间
	       laydate.render({
				elem : '#graduationTime'
	            ,format:'yyyy-MM-dd'
	            ,type:'date'
	            ,trigger: 'click'
	        });
	       //加载部门选择下拉框
			  $.ajax({
	           //几个参数需要注意一下
	               type: "POST",//方法类型
	               dataType: "json",//预期服务器返回的数据类型
	               url: "/depart/getAlldepartSelect",//url
	               data: {},
	               success: function (result) {
	               	if (result.code == "0") {
	               		var data=result.data;
	               		$("#empDepart").html('<option value="">请输入/选择部门</option>');
	               		if(data.length>0){
	               			for(i=0;i<data.length;i++){
	               				var temp=data[i];
	               				$("#empDepart").append('<option value="'+temp.departId+'">'+temp.departName+'</option>');
	               			}
	               			layui.form.render('select');
	               		}
	               		
	                 }else{
	                 	layer.msg('加载部门下拉框失败', {
	                         icon: 5
	                     });
	                 }
	               },
	               error : function() {
	               	layer.msg('加载部门下拉框失败', {
	                       icon: 5
	                   });
	               }
	           });
	   		
			form.on('submit(addAchives)',
				function(data) {
					var str = JSON.stringify(data.field)
					var param = JSON.parse(str);
					$.ajax({
						//几个参数需要注意一下
						type : "POST",//方法类型
						dataType : "json",//预期服务器返回的数据类型
						url : "/achives/addAchives",//url
						data : param,
						success : function(
								result) {
							if (result.code == "0") {
								var index = parent.layer
										.getFrameIndex(window.name); //先得到当前iframe层的索引
								parent.layer
										.close(index);
								parent.layer
										.msg('添加档案成功');
								parent.layui.table
										.reload(
												'achivesList',
												{
													page : {
														curr : 1
													}
												});
							} else if (result.code == "1") {
								layer
										.msg(
												'账号已存在',
												{
													icon : 5
												});
							} else {
								layer
										.msg(
												'服务器错误',
												{
													icon : 5
												});
							}
						},
						error : function() {
							layer
									.msg(
											'服务器错误',
											{
												icon : 5
											});
						}
					});

					return false;
				});
				//触发事件
				var active = {
					reset : function() {
						var index = parent.layer
								.getFrameIndex(window.name); //先得到当前iframe层的索引
						parent.layer.close(index);
						parent.layer.msg('已取消操作');
					}
				};
				$('#achivesAdd .layui-btn').on('click', function() {
					var type = $(this).data('type');
					active[type] ? active[type].call(this) : '';
				});

});
	</script>
</body>

</html>